public class test5 {
    /**
     * Definition for a binary tree node.
     * public class TreeNode {
     *     int val;
     *     TreeNode left;
     *     TreeNode right;
     *     TreeNode() {}
     *     TreeNode(int val) { this.val = val; }
     *     TreeNode(int val, TreeNode left, TreeNode right) {
     *         this.val = val;
     *         this.left = left;
     *         this.right = right;
     *     }
     * }
     */
    class Solution {
        public boolean isSymmetric(TreeNode root) {
            //左右==右左 ； 左左==右右
            if(root==null){
                return true;
            }
            return isVaild(root.left,root.right);
        }
        private boolean isVaild(TreeNode r1,TreeNode r2){
            if(r1==null && r2==null){
                return true;
            }else if(r1==null || r2==null){
                return false;
            }else if(r1.val!=r2.val){
                return false;
            }
            boolean b1 = isVaild(r1.left,r2.right);
            boolean b2 = isVaild(r1.right,r2.left);
            return b1 && b2;
        }
    }
}
